


import java.util.ArrayList;

public abstract class Piece {
	public static final int I_ID = 1;
	public static final int J_ID = 2;
	public static final int L_ID = 3;
	public static final int O_ID = 4;
	public static final int S_ID = 5;
	public static final int T_ID = 6;
	public static final int Z_ID = 7;
	private ArrayList<Block> my_blocks;
	private int x;
	private int y;
	int rotation;

	public Piece(int a_x,int a_y) {
		my_blocks = new ArrayList<Block>();
		rotation = 0;
		this.setX(a_x);
		this.setY(a_y);
		buildPiece();
	}

	public int getRotationNumber() {
		return rotation;
	}

	public void moveDown() {
		for (Block i : my_blocks) {
			i.setY(i.getY() + 1);
		}
		y++;
	}

	public void moveLeft() {
		for (Block i : my_blocks) {
			i.setX(i.getX() - 1);
		}
		x--;
	}

	public void moveRight() {
		for (Block i : my_blocks) {
			i.setX(i.getX() + 1);
		}
		x++;
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public void rotate(){
		if(rotation == 3){
			rotation = 0;
		}else{
			rotation++;
		}
	}

	public abstract void buildPiece();

	public void setPiece(ArrayList<Block> the_blocks) {
		my_blocks.clear();
		for (Block i : the_blocks) {
			my_blocks.add(new Block(i.getX(), i.getY(), i.getId()));
		}
	}
public void setX(int a_x){
	this.x = a_x;
}
public void setY(int a_y){
	this.y = a_y;
}
	public ArrayList<Block> getPiece() {
		ArrayList<Block> copy = new ArrayList<Block>();
		for (Block i : my_blocks) {
			copy.add(new Block(i.getX(), i.getY(), i.getId()));
		}
		return copy;
	}

}
